package com.atguigu.spzx.cloud.user.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.atguigu.spzx.cloud.model.entity.User;
import com.atguigu.spzx.cloud.user.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/api/user")
public class UserController {

    @Autowired
    private UserService userService ;

//    @Value("${key}")
//    public String key ;
    @SneakyThrows // 偷偷抛异常，如果正常执行什么事没有，如果不正常，抛出
    @SentinelResource("hot")
    @GetMapping(value = "/findUserByUserId/{userId}")
    public User findUserByUserId(@PathVariable(value = "userId") Long userId) {

//        System.out.println("key"+key);
//        String truth = request.getHeader("Truth");
//        System.out.println("truth"+truth);

        int i = 8/0;

        Thread.sleep(510);

        return userService.findUserByUserId(userId) ;
    }

}